/******************************************************************************
 * * setting_main.c - implementation of setting entry and common functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "setting_global.h"

Setting_NVM_Para_t g_SettingNvmPara;

BOOL               g_SettingSimStatus[2];                                   // TRUE: present, FALSE: absent
const INT8         g_SettingAcceptedCharsForNumberInput[] = "0123456789";   // used for valid chars can be accepted

// for SIM selection
VOID                       *gp_SettingSimSelectionCurUIDesc = NULL;         // Current UI description
SettingSimSelectedCallback gp_SettingSimSelectedCbFun;                      // Store the callback function after SIM1 or SIM2 selected
INT8                       *gp_SimTxt[2];                                   // Store the text for SIMx status display

// for setting done
// ACTIVITY_ID             g_SettingDoneCallerActId;
ACTIVITY_ID g_SettingDoneNextActId;
TIMER_ID    g_SettingAutoToNextActTimer = NULL;

// for setting error
// ACTIVITY_ID             g_SettingErrorCallerActId;
ACTIVITY_ID g_SettingErrorNextActId;
BOOL        g_SettingErrorAutoToNextActEnabled = FALSE;

VOID        *gp_SettingCurUIDesc      = NULL;                                    // Current Setting UI description
VOID        *gp_SettingOnOffCurUIDesc = NULL;                                    // Current Setting On Off UI description

static VOID Setting_Stop_AutoToNextActTimer(VOID);
/**
 * initiate setting module
 * param (in) void
 * return  void
 */
VOID Setting_Init_Req(VOID)
{
    NV_UI_Settings_t        *pNvUiSetting;
    Setting_Phone_Setting_t *PhoneSetting;
    If_Framework_Reg_Info_t *RegInfo;

    RegInfo = (If_Framework_Reg_Info_t *)Hal_Mem_Alloc(sizeof(If_Framework_Reg_Info_t));
    Hal_Mem_Set(RegInfo, 0, sizeof(If_Framework_Reg_Info_t));

    RegInfo->NameTextId = PHONE_TEXT_ID_SETTINGS;
    RegInfo->AppImage   = IMG_MENU_SETTING;
    RegInfo->AppFunc    = Display_Settings;

    Framework_App_Register_Req(RegInfo);

    // malloc memory for NVM reading buffer
    pNvUiSetting = Hal_Mem_Alloc(sizeof(NV_UI_Settings_t));

    // read NVM
    UI_NV_Read_Req(NV_SECTION_UI_SETTINGS, 0, sizeof(NV_UI_Settings_t), (UINT8 *)pNvUiSetting);

    // call sub module init functions
    Setting_Dualsim_Init_Req(pNvUiSetting);
    Setting_Profile_Init_Req(pNvUiSetting);
    Setting_Tone_Init_Req(pNvUiSetting);
    Setting_Display_Init_Req(pNvUiSetting);
    Setting_Time_Init_Req(pNvUiSetting);
    Setting_Call_Init_Req(pNvUiSetting);
    Setting_Phone_Init_Req(pNvUiSetting);
    Setting_Security_Init_Req(pNvUiSetting);

    // send init_cnf to framework
    PhoneSetting             = (Setting_Phone_Setting_t *)Hal_Mem_Alloc(sizeof(Setting_Phone_Setting_t));
    PhoneSetting->ChangeMark = 0;

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_DUAL_STAND_BY;
    if (SETTING_DEFAULT_DULT_SIM == pNvUiSetting->DualSimSetting.DefaultSim4Standby)
    {
        PhoneSetting->DualStandby = IF_SETTING_DUAL_SIM_STANDBY;
    }
    else if (SETTING_DEFAULT_SIM1 == pNvUiSetting->DualSimSetting.DefaultSim4Standby)
    {
        PhoneSetting->DualStandby = IF_SETTING_SIM_1_STANDBY;
    }
    else if (SETTING_DEFAULT_SIM2 == pNvUiSetting->DualSimSetting.DefaultSim4Standby)
    {
        PhoneSetting->DualStandby = IF_SETTING_SIM_2_STANDBY;
    }

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_NAME_OF_SIM1;
    Hal_Mem_Copy(PhoneSetting->NameOfSIM1, pNvUiSetting->DualSimSetting.SimName[0], NV_SETTING_MAX_SIM_NAME_LEN);

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_NAME_OF_SIM2;
    Hal_Mem_Copy(PhoneSetting->NameOfSIM2, pNvUiSetting->DualSimSetting.SimName[1], NV_SETTING_MAX_SIM_NAME_LEN);

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_WALL_PAPER;
    PhoneSetting->WallPaper   = SettingWallPaterList[pNvUiSetting->DisplaySetting.CurrentWallPaperIndex].WallPaper;

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_TIME_DISPLAY;
    if (SETTING_TIME_HIDE == pNvUiSetting->TimeSetting.TimeDisplay)
    {
        PhoneSetting->TimeDisplay.TimeDisplay = IF_SETTING_TIME_HIDE;
    }
    else
    {
        PhoneSetting->TimeDisplay.TimeDisplay = IF_SETTING_TIME_SHOW;
    }
    if (SETTING_TIME_FORMAT_12H == pNvUiSetting->TimeSetting.TimeFormat)
    {
        PhoneSetting->TimeDisplay.TimeFormat = IF_SETTING_TIME_FORMAT_12H;
    }
    else
    {
        PhoneSetting->TimeDisplay.TimeFormat = IF_SETTING_TIME_FORMAT_24H;
    }

    PhoneSetting->ChangeMark     |= IF_SETTING_CHANGE_MARK_CURRENT_LANGUAGE;
    if (0 == pNvUiSetting->PhoneSetting.CurrentLanguage)
    {
        PhoneSetting->CurrentLanguage = SETTING_LANGUAGE_EN;
    }
    else if (1 == pNvUiSetting->PhoneSetting.CurrentLanguage)
    {
        PhoneSetting->CurrentLanguage = SETTING_LANGUAGE_CN_SIMPLE;
    }
    else if (2 == pNvUiSetting->PhoneSetting.CurrentLanguage)
    {
        PhoneSetting->CurrentLanguage = SETTING_LANGUAGE_CN_TRADITIONAL;
    }

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_AUTO_GUARD_ON;
    PhoneSetting->AutoGuardOn = pNvUiSetting->PhoneSetting.AutoGuardOn;

    PhoneSetting->ChangeMark    |= IF_SETTING_CHANGE_MARK_AUTO_GUARD_DELAY;
    PhoneSetting->AutoGuardDelay = pNvUiSetting->PhoneSetting.AutoGuardDelay;

    PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_KEYGUARD_ON;
    PhoneSetting->KeyguardOn  = pNvUiSetting->PhoneSetting.KeyguardOn;

    PhoneSetting->ChangeMark   |= IF_SETTING_CHANGE_MARK_STARTUP_TONE_ON;
    PhoneSetting->StartupToneOn = pNvUiSetting->PhoneSetting.StartupToneOn;

    PhoneSetting->ChangeMark   |= IF_SETTING_CHANGE_MARK_WELCOME_NOTE_ON;
    PhoneSetting->WelcomeNoteOn = pNvUiSetting->PhoneSetting.WelcomeNoteOn;

    PhoneSetting->ChangeMark  |= IF_SETTING_CHANGE_MARK_FLIGHT_MODE_ON;
    PhoneSetting->FlightModeOn = pNvUiSetting->PhoneSetting.FlightModeOn;

    if (TRUE == PhoneSetting->WelcomeNoteOn)
    {
        PhoneSetting->ChangeMark |= IF_SETTING_CHANGE_MARK_WELCOME_NOTE;
        Hal_Mem_Copy(PhoneSetting->WelcomeNote, pNvUiSetting->PhoneSetting.WelcomeNote, IF_SETTING_MAX_WELCOME_NOTE_LEN);
    }

    PhoneSetting->ChangeMark       |= IF_SETTING_CHANGE_MARK_STANDBY_SCREEN_MODE;
    if (0 == pNvUiSetting->DisplaySetting.StandbyScreenMode)
    {
        PhoneSetting->StandbyScreenMode = IF_SETTING_STANDBY_SCREEN_OFF;
    }
    else if (1 == pNvUiSetting->DisplaySetting.StandbyScreenMode)
    {
        PhoneSetting->StandbyScreenMode = IF_SETTING_STANDBY_SCREEN_ON;
    }

    Setting_Init_Cnf(PhoneSetting);

    // free the nvm reading buffer
    Hal_Mem_Free(pNvUiSetting);
} /* Setting_Init_Req */

/**
 * entry of setting APP
 * param (in) void
 * return  void
 */
VOID Setting_Main(VOID)
{
    // APP UI entry
    // create setting list and band sub-module entry
}

/**
 * setting event handler
 * param (in) void
 * return  void
 */
VOID Setting_Event_handle(VOID)
{
    // event and message dispatch
}

/**
 * Key Callback Function of Setting
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Settings_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8                      Ret                 = 0;
    UINT8                      Index               = 0;
    UI_Normal_List_Only_Desc_t *NormalListOnlyDesc = NULL;

    if (KEY_RELEASED != key_sta)
    {
        return(Ret);
    }

    NormalListOnlyDesc = (UI_Normal_List_Only_Desc_t *)gp_SettingCurUIDesc;
    Index              = NormalListOnlyDesc->List.Index;

    if (KEY_DOWN == key_val)
    {
        Index++;
        Index                         %= NormalListOnlyDesc->List.ListButtonCnt;
        NormalListOnlyDesc->List.Index = Index;
    }
    else if (KEY_UP == key_val)
    {
        Index += NormalListOnlyDesc->List.ListButtonCnt;
        Index--;
        Index                         %= NormalListOnlyDesc->List.ListButtonCnt;
        NormalListOnlyDesc->List.Index = Index;
    }
    else if (KEY_SOFTRIGHT == key_val)
    {   // return to previous UI
        Nav_Back(ACT_ID_ANY);
        Ret = 1;
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        Ret = 1;
    }

    return(Ret);
}

/**
 * display Settings
 * param (in) CallerActId   : UI_PHONE_TEXT_ID, the activity Id from which entered main setting screen
 * return void:
 */
VOID Display_Settings(VOID)
{
    // Settings
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;
    UINT8                      i                  = 0;
    Nav_Func_List_t            FuncList;
    UINT8                      ItemCnt            = 0;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_SETTINGS;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalLstOnlyDesc->List.Index = 0;
    if ((FALSE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (FALSE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        ItemCnt = 9;
    }
    else
    {
        ItemCnt = 10;
    }
#if USE_LV_BLUETOOTH != 0
    ItemCnt = ItemCnt + 1;
#endif
#if USE_LV_WLAN != 0
    ItemCnt = ItemCnt + 1;
#endif
    NormalLstOnlyDesc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * ItemCnt);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, (sizeof(UI_Button_Desc_t) * ItemCnt));

    if ((TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1]) || (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
        NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
        NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_DSIM;
        NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_DUALSIM_SETTING;
        NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Dual_Sim_Settings_Cb;
    }
    #if USE_LV_BLUETOOTH != 0
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = LV_SYMBOL_BLUETOOTH;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_BLUETOOTH;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Bluetooth_Cb;
    #endif

#if USE_LV_WLAN != 0
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = LV_SYMBOL_WIFI;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_WLAN;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Wlan_Cb;
#endif

    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_TONE;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_TONE_SETTINGS;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Tone_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_DISPLAY;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_DISPLAY_SETTINGS;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Display_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = LV_SYMBOL_GPS;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_VOLTE_SWITCH;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Volte_Switch_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_PROFILE;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_PROFILES;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Profiles_List_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_TIME;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_TIME_SET;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Time_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = LV_SYMBOL_CALL;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_CALL_SETTINGS;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Call_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_PHONE;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_PHONE_SETTINGS;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Phone_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_SECURITY;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_SECURITY_SETTINGS;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Security_Settings_Cb;
    NormalLstOnlyDesc->List.ButtonList[i].Valid        = TRUE;
    NormalLstOnlyDesc->List.ButtonList[i].ButtonIndex  = i;
    NormalLstOnlyDesc->List.ButtonList[i].SymbolId1    = SYMBOL_RESET;
    NormalLstOnlyDesc->List.ButtonList[i].TxtId        = PHONE_TEXT_ID_RESET;
    NormalLstOnlyDesc->List.ButtonList[i++].ReleaseFun = Display_Setting_Security_Restore_Factory_Cb;

    NormalLstOnlyDesc->List.ListButtonCnt = i;

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Settings_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow = UI_Normal_List_Only_Create;

    gp_SettingCurUIDesc = (VOID *)NormalLstOnlyDesc;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING, &FuncList, (VOID *)NormalLstOnlyDesc);
} /* Display_Settings */

lv_res_t Display_Settings_Cb(lv_obj_t *Btn)
{
    Display_Settings();

    return(LV_RES_OK);
}

/**
 *
 * Callback of Settings_SIM_Selection, on create
 * param (in) pPara: VOID*, pointer of UI_Normal_Container_List_Desc_t
 * return void:
 */
VOID Display_Setting_SIM_Selection_Create(VOID *pPara)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

    // lv_theme_t                      *theme              = lv_theme_get_current();

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)pPara;

    if ((NULL != gp_SimTxt[0]) && (LV_LANG_TXT_ID_NONE == pNormalContLstDesc->ContList.ContainerList[0].u.Label2.TxtId))
    {
        lv_label_set_text(pNormalContLstDesc->ContList.ContainerList[0].u.Label2.Label, gp_SimTxt[0]);
    }

    if ((NULL != gp_SimTxt[1]) && (LV_LANG_TXT_ID_NONE == pNormalContLstDesc->ContList.ContainerList[1].u.Label2.TxtId))
    {
        lv_label_set_text(pNormalContLstDesc->ContList.ContainerList[1].u.Label2.Label, gp_SimTxt[1]);
    }

    if ((FALSE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        lv_btn_set_state(pNormalContLstDesc->ContList.ContainerList[0].Button, LV_BTN_STATE_DISABLED);
        // lv_label_set_style(pNormalContLstDesc->ContList.ContainerList[0].Label.Label, theme->label.hint);
        // lv_label_set_style(pNormalContLstDesc->ContList.ContainerList[0].u.Label2.Label, theme->label.hint);
    }
    if ((TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (FALSE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        lv_btn_set_state(pNormalContLstDesc->ContList.ContainerList[1].Button, LV_BTN_STATE_DISABLED);
        // lv_label_set_style(pNormalContLstDesc->ContList.ContainerList[1].Label.Label, theme->label.hint);
        // lv_label_set_style(pNormalContLstDesc->ContList.ContainerList[1].u.Label2.Label, theme->label.hint);
    }
}

/**
 *
 * Callback of Settings_SIM_Selection, on destroy
 * param (in) pPara: VOID*, pointer of UI_Normal_Container_List_Desc_t
 * return void:
 */
VOID Display_Setting_SIM_Selection_Destroy(VOID *pPara)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)pPara;

    Hal_Mem_Free(pNormalContLstDesc->ContList.ContainerList);
    Hal_Mem_Free(pNormalContLstDesc);
    if(NULL != gp_SimTxt[0]) {
        Hal_Mem_Free(gp_SimTxt[0]);
        gp_SimTxt[0] = NULL;
    }
    if(NULL != gp_SimTxt[1]) {
        Hal_Mem_Free(gp_SimTxt[1]);
        gp_SimTxt[1] = NULL;
    }
}

/**
 *
 * Callback of Settings_SIM_Selection, on restore state
 * param (in) pPara: VOID*, pointer of UI_Normal_Container_List_Desc_t
 * return void:
 */
VOID Display_Setting_SIM_Selection_RestoreState(VOID *pPara)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)pPara;

    Display_Setting_SIM_Selection_Create(pNormalContLstDesc);
    gp_SettingSimSelectionCurUIDesc = (VOID *)pNormalContLstDesc;
}

/**
 *
 * Callback of Settings_SIM_Selection, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_SIM_Selection_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc;

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)gp_SettingSimSelectionCurUIDesc;

    if (KEY_DOWN == key_val)
    {
        pNormalContLstDesc->ContList.Index++;
        pNormalContLstDesc->ContList.Index %= pNormalContLstDesc->ContList.ListContainerCnt;
        return(0);
    }
    else if (KEY_UP == key_val)
    {
        pNormalContLstDesc->ContList.Index += pNormalContLstDesc->ContList.ListContainerCnt;
        pNormalContLstDesc->ContList.Index--;
        pNormalContLstDesc->ContList.Index %= pNormalContLstDesc->ContList.ListContainerCnt;
        return(0);
    }
    else if (KEY_OK == key_val)
    {
        if (0 == pNormalContLstDesc->ContList.Index)     // SIM1 selected
        {
            // if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1])
            // {
            gp_SettingSimSelectedCbFun(MMI_MODEM_SIM_1);
            // }
        }
        else                                            // SIM2 selected
        {
            // if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2])
            // {
            gp_SettingSimSelectedCbFun(MMI_MODEM_SIM_2);
            // }
        }
        return(1);
    }
    else if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_ANY);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
} /* Display_Setting_SIM_Selection_KeyCb */

/**
 * display Settings_SIM_Selection
 * param (in) CallerActId   : ACTIVITY_ID, the activity Id from which entered SIM selection screen
 *       (in) Sim1ValueTxtId: UI_PHONE_TEXT_ID
 *       (in) Sim2ValueTxtId: UI_PHONE_TEXT_ID
 *       (in) Sim1Txt       : INT8*
 *       (in) Sim2Txt       : INT8*
 *       (in) SimActionCb   : SettingSimSelectedCallback
 * return void:
 */
VOID Display_Setting_SIM_Selection(ACTIVITY_ID                CallerActId,
                                   UI_PHONE_TEXT_ID           Sim1ValueTxtId,
                                   UI_PHONE_TEXT_ID           Sim2ValueTxtId,
                                   INT8                       *Sim1Txt,
                                   INT8                       *Sim2Txt,
                                   SettingSimSelectedCallback SimActionCb)
{
    Nav_Func_List_t                 FuncList;
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc;

    UINT8                           SimTxtLen;

    // Alloc memory for time setting UI display
    pNormalContLstDesc = Hal_Mem_Alloc(sizeof(UI_Normal_Container_List_Desc_t));
    Hal_Mem_Set(pNormalContLstDesc, 0, sizeof(UI_Normal_Container_List_Desc_t));

    pNormalContLstDesc->TitleBar.TxtId      = PHONE_TEXT_ID_SIM_SEL;
    pNormalContLstDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pNormalContLstDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    pNormalContLstDesc->ContList.ListContainerCnt = 2;
    pNormalContLstDesc->ContList.Index            = 0;
    pNormalContLstDesc->ContList.ContainerList    = Hal_Mem_Alloc(sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt);
    Hal_Mem_Set(pNormalContLstDesc->ContList.ContainerList, 0, (sizeof(UI_Container_Base_Desc_t) * pNormalContLstDesc->ContList.ListContainerCnt));

    pNormalContLstDesc->ContList.ContainerList[0].Label.TxtId      = PHONE_TEXT_ID_SIM1;
    pNormalContLstDesc->ContList.ContainerList[0].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pNormalContLstDesc->ContList.ContainerList[0].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pNormalContLstDesc->ContList.ContainerList[0].Valid            = TRUE;
    if ((LV_LANG_TXT_ID_NONE == Sim1ValueTxtId) && (NULL == Sim1Txt))
    {
        pNormalContLstDesc->ContList.ContainerList[0].Choise = UI_BASE_OBJ_NULL;
    }
    else
    {
        pNormalContLstDesc->ContList.ContainerList[0].Choise              = UI_BASE_OBJ_LABEL;
        pNormalContLstDesc->ContList.ContainerList[0].u.Label2.TxtId      = Sim1ValueTxtId;
        pNormalContLstDesc->ContList.ContainerList[0].u.Label2.TxtAlign   = LV_LABEL_ALIGN_RIGHT;
        pNormalContLstDesc->ContList.ContainerList[0].u.Label2.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    }

    pNormalContLstDesc->ContList.ContainerList[1].Label.TxtId      = PHONE_TEXT_ID_SIM2;
    pNormalContLstDesc->ContList.ContainerList[1].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pNormalContLstDesc->ContList.ContainerList[1].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pNormalContLstDesc->ContList.ContainerList[1].Valid            = TRUE;
    if ((LV_LANG_TXT_ID_NONE == Sim2ValueTxtId) && (NULL == Sim2Txt))
    {
        pNormalContLstDesc->ContList.ContainerList[1].Choise = UI_BASE_OBJ_NULL;
    }
    else
    {
        pNormalContLstDesc->ContList.ContainerList[1].Choise              = UI_BASE_OBJ_LABEL;
        pNormalContLstDesc->ContList.ContainerList[1].u.Label2.TxtId      = Sim2ValueTxtId;
        pNormalContLstDesc->ContList.ContainerList[1].u.Label2.TxtAlign   = LV_LABEL_ALIGN_RIGHT;
        pNormalContLstDesc->ContList.ContainerList[1].u.Label2.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    }

    pNormalContLstDesc->ButtonBar.ButtonL.Valid       = FALSE;
    pNormalContLstDesc->ButtonBar.ButtonM.Valid       = TRUE;
    pNormalContLstDesc->ButtonBar.ButtonM.ButtonIndex = 1;
    pNormalContLstDesc->ButtonBar.ButtonM.TxtId       = PHONE_TEXT_ID_SELECT;
    pNormalContLstDesc->ButtonBar.ButtonR.Valid       = TRUE;
    pNormalContLstDesc->ButtonBar.ButtonR.ButtonIndex = 2;
    pNormalContLstDesc->ButtonBar.ButtonR.TxtId       = PHONE_TEXT_ID_BACK;

    pNormalContLstDesc->KeyFunc = Display_Setting_SIM_Selection_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_Container_List_Create;
    FuncList.OnCreate       = Display_Setting_SIM_Selection_Create;
    FuncList.OnDestroy      = Display_Setting_SIM_Selection_Destroy;
    FuncList.OnRestoreState = Display_Setting_SIM_Selection_RestoreState;

    gp_SettingSimSelectionCurUIDesc = (VOID *)pNormalContLstDesc;
    gp_SettingSimSelectedCbFun      = SimActionCb;

    if (NULL != Sim1Txt)
    {
        SimTxtLen    = strlen(Sim1Txt) + 1;
        gp_SimTxt[0] = (INT8 *)Hal_Mem_Alloc(SimTxtLen);
        Hal_Mem_Copy(gp_SimTxt[0], Sim1Txt, SimTxtLen);
        Hal_Mem_Free(Sim1Txt);
    }

    if (NULL != Sim2Txt)
    {
        SimTxtLen    = strlen(Sim2Txt) + 1;
        gp_SimTxt[1] = (INT8 *)Hal_Mem_Alloc(SimTxtLen);
        Hal_Mem_Copy(gp_SimTxt[1], Sim2Txt, SimTxtLen);
        Hal_Mem_Free(Sim2Txt);
    }

    Nav_Forward(CallerActId, ACT_ID_SETTING_SIM_SELECTION, &FuncList, pNormalContLstDesc);
} /* Display_Setting_SIM_Selection */

/**
 * Set parameter of UI Settings_SIM_Selection
 * param (in) Sim1ValueTxtId: UI_PHONE_TEXT_ID
 *       (in) Sim2ValueTxtId: UI_PHONE_TEXT_ID
 *       (in) Sim1Txt       : INT8*
 *       (in) Sim2Txt       : INT8*
 * return void:
 */
VOID Display_Setting_SIM_Selection_Set(UI_PHONE_TEXT_ID Sim1ValueTxtId,
                                       UI_PHONE_TEXT_ID Sim2ValueTxtId,
                                       INT8             *Sim1Txt,
                                       INT8             *Sim2Txt)
{
    UI_Normal_Container_List_Desc_t *pNormalContLstDesc = NULL;
    UINT8                           SimTxtLen           = 0;

    pNormalContLstDesc = (UI_Normal_Container_List_Desc_t *)gp_SettingSimSelectionCurUIDesc;

    if (LV_LANG_TXT_ID_NONE != Sim1ValueTxtId)
    {
        pNormalContLstDesc->ContList.ContainerList[0].u.Label2.TxtId = Sim1ValueTxtId;
    }

    if (LV_LANG_TXT_ID_NONE != Sim2ValueTxtId)
    {
        pNormalContLstDesc->ContList.ContainerList[1].u.Label2.TxtId = Sim2ValueTxtId;
    }

    if (NULL != Sim1Txt)
    {
        pNormalContLstDesc->ContList.ContainerList[0].u.Label2.TxtId = LV_LANG_TXT_ID_NONE;

        Hal_Mem_Free(gp_SimTxt[0]);
        SimTxtLen    = strlen(Sim1Txt) + 1;
        gp_SimTxt[0] = (INT8 *)Hal_Mem_Alloc(SimTxtLen);
        Hal_Mem_Copy(gp_SimTxt[0], Sim1Txt, SimTxtLen);
        Hal_Mem_Free(Sim1Txt);
    }

    if (NULL != Sim2Txt)
    {
        pNormalContLstDesc->ContList.ContainerList[1].u.Label2.TxtId = LV_LANG_TXT_ID_NONE;

        Hal_Mem_Free(gp_SimTxt[1]);
        SimTxtLen    = strlen(Sim2Txt) + 1;
        gp_SimTxt[1] = (INT8 *)Hal_Mem_Alloc(SimTxtLen);
        Hal_Mem_Copy(gp_SimTxt[1], Sim2Txt, SimTxtLen);
        Hal_Mem_Free(Sim2Txt);
    }
}

/**
 *
 * Callback of Setting module, auto-back timer
 * param (in) Para: UINT32
 * return void:
 */
VOID Display_Setting_AutoToNextAct_Timeout(VOID* Para)
{
    ACTIVITY_ID* ActId = (ACTIVITY_ID*)Para;
    g_SettingAutoToNextActTimer = NULL;
    if(*ActId != Nav_Get_Top()) {
        printf("top setting act is not present");
        // return;
    }

    if (*ActId == ACT_ID_SETTING_CODE_ERROR)
    {
        Nav_Forward(ACT_ID_SETTING_CODE_ERROR, g_SettingErrorNextActId, NULL, NULL);
    }
    else if (*ActId == ACT_ID_SETTING_DONE)
    {
        // Nav_Forward(ACT_ID_SETTING_DONE, g_SettingDoneNextActId, NULL, NULL);

        if (ACT_ID_SETTING_SIM_SELECTION == g_SettingDoneNextActId)
        {
            Nav_Forward(ACT_ID_SETTING_DONE, g_SettingDoneNextActId, NULL, gp_SettingSimSelectionCurUIDesc);
            Display_Setting_SIM_Selection_Create(gp_SettingSimSelectionCurUIDesc);
        }
        else if (ACT_ID_DESKTOP == g_SettingDoneNextActId)
        {
            printf("Return to desktop, Display_Setting_AutoToNextAct_Timeout\n");
            Nav_Home(ACT_ID_SETTING_DONE);
        }
        else
        {
            Nav_Forward(ACT_ID_SETTING_DONE, g_SettingDoneNextActId, NULL, NULL);
        }
    }
}

/**
 *
 * Callback of Setting_Done, on create
 * param (in) pPara: VOID*
 * return void:
 */
VOID Display_Setting_Done_Create(VOID *pPara)
{
    // Create & start 2s auto-back timer
    static ACTIVITY_ID Para = ACT_ID_SETTING_DONE;
    g_SettingAutoToNextActTimer = Hal_Timer_Start(2000, Display_Setting_AutoToNextAct_Timeout, (VOID *)&Para, FALSE);
}

/**
 *
 * Callback of Settings_Done, on destroy
 * param (in) pPara: VOID*, pointer of UI_Status_Desc_t
 * return void:
 */
VOID Display_Setting_Done_Destroy(VOID *pPara)
{
    Hal_Mem_Free(pPara);
}

/**
 *
 * Callback of Setting_Done, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Done_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_END == key_val)
    {
        Setting_Stop_AutoToNextActTimer();
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Setting_Done
 * param (in) CallerActId   : ACTIVITY_ID, the activity Id from which entered setting done screen
 *       (in) TxtId         : UI_PHONE_TEXT_ID, the text shown on screen
 *       (in) AutoNextActId : ACTIVITY_ID, the next activity Id auto entered from setting_done
 * return void:
 */
VOID Display_Setting_Done(ACTIVITY_ID      CallerActId,
                          UI_PHONE_TEXT_ID TxtId,
                          ACTIVITY_ID      AutoNextActId)
{
    UI_Status_Desc_t *StatusDesc;
    Nav_Func_List_t  FuncList;

    StatusDesc = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(StatusDesc, 0, sizeof(UI_Status_Desc_t));

    StatusDesc->ContLabel.TxtId      = TxtId;
    StatusDesc->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    StatusDesc->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    StatusDesc->ContImg.Img          = LV_SYMBOL_OK;
    StatusDesc->ContImg.ImgAlign     = LV_ALIGN_IN_TOP_RIGHT;
    StatusDesc->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    StatusDesc->KeyFunc = Display_Setting_Done_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Status_Create;
    FuncList.OnCreate  = Display_Setting_Done_Create;
    FuncList.OnDestroy = Display_Setting_Done_Destroy;

    // g_SettingDoneCallerActId = CallerActId;
    g_SettingDoneNextActId = AutoNextActId;
    Nav_Forward(CallerActId, ACT_ID_SETTING_DONE, &FuncList, (VOID *)StatusDesc);
}

/**
 *
 * Callback of Settings_On_Off, on destroy
 * param (in) pPara: VOID*, pointer of UI_Normal_List_Only_Desc_t
 * return void:
 */
VOID Display_Setting_On_Off_Destroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalLstOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalLstOnlyDesc);
}

/**
 *
 * Callback of Setting_On_Off, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_On_Off_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;
    UINT8                      Index              = 0;

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)gp_SettingOnOffCurUIDesc;
    Index             = NormalLstOnlyDesc->List.Index;

    if (KEY_DOWN == key_val)
    {
        Index++;
        Index                        %= NormalLstOnlyDesc->List.ListButtonCnt;
        NormalLstOnlyDesc->List.Index = Index;
        return(0);
    }
    else if (KEY_UP == key_val)
    {
        Index += NormalLstOnlyDesc->List.ListButtonCnt;
        Index--;
        Index                        %= NormalLstOnlyDesc->List.ListButtonCnt;
        NormalLstOnlyDesc->List.Index = Index;
        return(0);
    }
    else if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_ANY);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
} /* Display_Setting_On_Off_KeyCb */

/**
 * display Setting_On_Off
 * param (in) CallerActId   : ACTIVITY_ID, the activity Id from which entered setting_ON/OFF screen
 *       (in) TitleTxtId    : UI_PHONE_TEXT_ID, the text shown on title
 *       (in) CurSetting    : UINT8, current setting(0--OFF, 1--ON)
 *       (in) OnActionCb    : lv_event_cb_t, callback function when "ON" selected
 *       (in) OffActionCb   : lv_event_cb_t, callback function when "OFF" selected
 * return void:
 */
VOID Display_Setting_On_Off(ACTIVITY_ID      CallerActId,
                            UI_PHONE_TEXT_ID TitleTxtId,
                            UINT8            CurSetting,
                            lv_event_cb_t    OnActionCb,
                            lv_event_cb_t    OffActionCb)
{
    //
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = TitleTxtId;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    if (0 == CurSetting)
    {
        NormalLstOnlyDesc->List.Index = 1;
    }
    else
    {
        NormalLstOnlyDesc->List.Index = 0;
    }
    NormalLstOnlyDesc->List.ListButtonCnt = 2;
    NormalLstOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 2);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t) * 2);

    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_ON;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  = OnActionCb;
    NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
    NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_OFF;
    NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  = OffActionCb;

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Setting_On_Off_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Setting_On_Off_Destroy;

    Nav_Forward(CallerActId, ACT_ID_SETTING_ON_OFF, &FuncList, (VOID *)NormalLstOnlyDesc);
    gp_SettingOnOffCurUIDesc = (VOID *)NormalLstOnlyDesc;
} /* Display_Setting_On_Off */

/**
 *
 * Callback of Setting_Error, on create
 * param (in) pPara: VOID*
 * return void:
 */
VOID Display_Setting_Error_Create(VOID *pPara)
{
    // Create & start 2s auto-back timer
    if (TRUE == g_SettingErrorAutoToNextActEnabled)
    {
        static ACTIVITY_ID Para = ACT_ID_SETTING_CODE_ERROR;
        g_SettingAutoToNextActTimer = Hal_Timer_Start(2000, Display_Setting_AutoToNextAct_Timeout, (VOID *)&Para, FALSE);
    }
}

/**
 *
 * Callback of Settings_Error, on destroy
 * param (in) pPara: VOID*, pointer of UI_Normal_NoTitle_Desc_t
 * return void:
 */
VOID Display_Setting_Error_Destroy(VOID *pPara)
{
    Hal_Mem_Free(pPara);
}

/**
 *
 * Callback of Setting_Error, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Error_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_OK == key_val)
    {
        if (FALSE == g_SettingErrorAutoToNextActEnabled)
        {
            Setting_Stop_AutoToNextActTimer();
            Nav_Forward(ACT_ID_SETTING_CODE_ERROR, g_SettingErrorNextActId, NULL, NULL);
        }
        return(0);
    }
    else if (KEY_END == key_val)
    {
        Setting_Stop_AutoToNextActTimer();
        if (SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK ==
            g_SettingSecuritySettingMng.OperatingAction)
        {
            // Hal_Timer_Stop(g_SettingAutoToNextActTimer);
            Nav_Back(ACT_ID_ANY);
        }
        else
        {
            // Hal_Time_Stop(g_SettingAutoToNextActTimer);
            Nav_Home(ACT_ID_ANY);
        }
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Setting_Error
 * param (in) CallerActId         : ACTIVITY_ID, the activity Id from which entered setting_error screen
 *       (in) TxtId               : UI_PHONE_TEXT_ID, the text shown on screen
 *       (in) NextActId           : ACTIVITY_ID, the next activity Id
 *       (in) AutoToNextActEnabled: BOOL, whether auto to next activity Id by timer
 * return void:
 */
VOID Display_Setting_Error(ACTIVITY_ID      CallerActId,
                           UI_PHONE_TEXT_ID TxtId,
                           ACTIVITY_ID      NextActId,
                           BOOL             AutoToNextActEnabled)
{
    UI_Normal_NoTitle_Desc_t *NormalNoTitleDesc;
    Nav_Func_List_t          FuncList;

    NormalNoTitleDesc = (UI_Normal_NoTitle_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Desc_t));
    Hal_Mem_Set(NormalNoTitleDesc, 0, sizeof(UI_Normal_NoTitle_Desc_t));

    NormalNoTitleDesc->ContenCont.ContLabel.TxtId       = TxtId;
    NormalNoTitleDesc->ContenCont.ContLabel.TxtAlign    = LV_LABEL_ALIGN_LEFT;
    NormalNoTitleDesc->ContenCont.ContLabel.LabelAlign  = LV_ALIGN_IN_TOP_LEFT;
    NormalNoTitleDesc->ContenCont.ContLabelAlign        = LV_ALIGN_IN_TOP_LEFT;

    NormalNoTitleDesc->ContenCont.ContImg.Img  = LV_SYMBOL_WARNING;
    NormalNoTitleDesc->ContenCont.ContImgAlign = LV_ALIGN_IN_TOP_RIGHT;

    NormalNoTitleDesc->ButtonBar.ButtonL.Valid = FALSE;
    if (FALSE == AutoToNextActEnabled)
    {
        NormalNoTitleDesc->ButtonBar.ButtonM.Valid = TRUE;
        NormalNoTitleDesc->ButtonBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    }
    else
    {
        NormalNoTitleDesc->ButtonBar.ButtonM.Valid = FALSE;
    }
    NormalNoTitleDesc->ButtonBar.ButtonR.Valid = FALSE;

    NormalNoTitleDesc->KeyFunc = Display_Setting_Error_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_NoTitle_Create;
    FuncList.OnCreate  = Display_Setting_Error_Create;
    FuncList.OnDestroy = Display_Setting_Error_Destroy;

    // g_SettingErrorCallerActId = CallerActId;
    g_SettingErrorNextActId            = NextActId;
    g_SettingErrorAutoToNextActEnabled = AutoToNextActEnabled;
    Nav_Forward(CallerActId, ACT_ID_SETTING_CODE_ERROR, &FuncList, (VOID *)NormalNoTitleDesc);
}

VOID Setting_Set_Sim_Status(MMI_MODEM_SIM_ID simId, BOOL simStatus)
{
    printf("%s: simid %d, sta %d\n", __FUNCTION__, simId, simStatus);
    g_SettingSimStatus[simId] = simStatus;
}

VOID Setting_Stop_AutoToNextActTimer(VOID)
{
    if(NULL != g_SettingAutoToNextActTimer) {
        printf("%s\n", __FUNCTION__);
        Hal_Timer_Stop(g_SettingAutoToNextActTimer);
        g_SettingAutoToNextActTimer = NULL;
    }
}
